﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent

Partial Class rtrans
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        Else
            lblStaffUID.Text = Session("StaffId").ToString
            lblStaffType.Text = Session("StaffType").ToString
        End If

        'Note to Developer Session.Add("Type","Renew") <- detect it comes from renew
        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            If Not Session("Tid").ToString Is Nothing Then
                lblTransUID.Text = Session("Tid").ToString
                'Me.Session.Remove("Tid")
                LoadrbtTransactAs()
                LoadTransInfo()
                Dim strCoBroke As String = String.Empty
                If lblhidCoBrokeAgencyName.Text <> String.Empty Then
                    strCoBroke += "Agency Name : " & lblhidCoBrokeAgencyName.Text.Trim & "<br />"
                End If
                If lblhidCoBrokePhone.Text <> String.Empty Then
                    strCoBroke += "Phone : " & lblhidCoBrokePhone.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeMobile.Text <> String.Empty Then
                    strCoBroke += "Mobile : " & lblhidCoBrokeMobile.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeFax.Text <> String.Empty Then
                    strCoBroke += "Fax : " & lblhidCoBrokeFax.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeEmail.Text <> String.Empty Then
                    strCoBroke += "Email : " & lblhidCoBrokeEmail.Text.Trim & "<br />"
                End If
                lblCoBroke.Attributes.Add("onmouseover", "return overlib('" & strCoBroke & "',ABOVE);")
            Else
                Response.Redirect("TransList.aspx")
            End If
        End If
    End Sub

    Private Sub LoadrbtTransactAs()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT RRYes, RCYes, RLYes, RIYes FROM AW_Property p INNER JOIN AW_RentTransaction r " & _
                                    "ON p.PropertyId = r.PropertyId WHERE TransactionId = @TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text.Trim))
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        If TempDT.Rows.Count > 0 Then
            For Each row As Data.DataRow In TempDT.Rows
                If row.Item("RRYes").ToString = "1" Then
                    rbtTransactAs.Items.Add(New ListItem("RR", "1"))
                End If
                If row.Item("RCYes").ToString = "1" Then
                    rbtTransactAs.Items.Add(New ListItem("RC", "2"))
                End If
                If row.Item("RLYes").ToString = "1" Then
                    rbtTransactAs.Items.Add(New ListItem("RL", "3"))
                End If
                If row.Item("RIYes").ToString = "1" Then
                    rbtTransactAs.Items.Add(New ListItem("RI", "4"))
                End If
            Next
        Else

        End If
       
    End Sub

    Private Sub LoadTransInfo()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT t.TransactionId, t.PropertyId, t.OpenFileRef, t.CloseFileRef, t.Renewed, " & _
                                "p.UnitNumber + ', ' + r.Road + ', ' + o.Location + ', ' + s.State + ', ' + y.Country as 'Address', " & _
                                "j.Project, t.ListerId, t.TransactorId, L.Name as Lister, L.Initial as ListerInitial, t.ListDate, t.LandlordType, t.LandlordName1, t.LandlordName2, " & _
                                "t.LandlordName3, t.LandlordCompany, t.LandlordNRIC1, t.LandlordNRIC2, t.LandlordNRIC3, a.Name as Transactor, a.Initial as TransactorInitial, " & _
                                "t.LandlordCompanyNo, ISNULL(t.LandlordAddress, p.LandlordAddress) as 'LandlordAddress' , " & _
                                "ISNULL(t.LandlordPhone, p.LandlordPhone) as 'LandlordPhone', ISNULL(t.LandlordMobile, p.LandlordMobile) as 'LandlordMobile', " & _
                                "ISNULL(t.LandlordFax, p.LandlordFax) as 'LandlordFax', ISNULL(t.LandlordContactPerson, p.LandlordName) as 'LandlordContactPerson', " & _
                                "t.LandlordEmail, t.LandlordReferral, t.LandlordReferralName, t.LandlordReferralNRIC, t.TransactDate, " & _
                                "t.LandlordReferralContact, t.LandlordReferralStatus, t.LandlordReferralAmount, t.LandlordReferralAmtSum, " & _
                                "t.LandlordViewMeetTele, t.LandlordIncomeTax, t.LandlordTAFee, t.AgencyFee, t.GST, t.GSTPaidBy, t.ListingFee, " & _
                                "t.TenantType, t.TenantName1, t.TenantName2, t.TenantName3, t.TenantCompany, " & _
                                "t.TenantNRIC1, t.TenantNRIC2, t.TenantNRIC3, t.TenantCompanyNo, t.TenantAddress, " & _
                                "t.TenantPhone, t.TenantMobile, t.TenantFax, t.TenantEmail, t.TenantReferral, " & _
                                "t.TenantReferralName, t.TenantReferralNRIC, t.TenantReferralContact, t.TenantViewMeetTele, t.TenantIncomeTax, " & _
                                "t.TenantReferralStatus, t.TenantReferralAmount, t.TenantReferralAmtSum, t.TenantContactPerson, " & _
                                "t.DisbursementFee, t.CoBroke, t.Deposit, t.DepositMonth, t.Advance, t.AdvanceMonth, t.WaterElectric, t.Tel, t.TenantTAFee, " & _
                                "t.CoBrokeId, c.Name as CoBrokeName, c.AgencyName as CoBrokeAgencyName, c.Phone as CoBrokePhone, " & _
                                "c.Mobile as CobrokeMobile, c.Fax as CobrokeFax, c.Email as cobrokeEmail, t.TransListType, " & _
                                "t.MonthlyRental, t.TenancyDuration, t.TenancyDurationType, t.Requisition, t.TerminationClause, t.PremiseUse, " & _
                                "t.TotalAgencyFee, t.ListerAmt, t.ReferralAmt, t.GovAmt, t.GrossAmount, TotalTA, StampDuty, p.RListerId " & _
                                "FROM AW_RentTransaction t LEFT JOIN AW_Staff L on t.ListerId = L.StaffId LEFT JOIN AW_Staff a on t.TransactorId = a.StaffId " & _
                                "LEFT JOIN AW_CoBroke c on t.CoBrokeId = c.CoBrokeId LEFT OUTER JOIN AW_Property p ON p.PropertyId = t.PropertyId " & _
                                "LEFT OUTER JOIN AW_Road r ON p.RoadId = r.RoadId LEFT OUTER JOIN AW_Location o ON r.LocationId = o.LocationId " & _
                                "LEFT OUTER JOIN AW_State s ON o.StateId = s.StateId LEFT OUTER JOIN AW_Country y ON s.CountryId = y.CountryId " & _
                                "LEFT OUTER JOIN AW_Project j ON p.ProjectId = j.ProjectId WHERE TransactionID=@TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text.Trim))
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        For Each ReadRow As Data.DataRow In TempDT.Rows
            'edited by minginn @ 13/6/2011 - add in to differentiate trans from renew button or transact
            If ReadRow.Item("Renewed").ToString = "1" Then
                txtLandlordName1.Enabled = False
                txtLandlordName2.Enabled = False
                txtLandlordName3.Enabled = False
                txtLandlordCompanyName.Enabled = False
                txtLandlordNric1.Enabled = False
                txtLandlordNric2.Enabled = False
                txtLandlordNric3.Enabled = False
                txtLandlordCompanyNo.Enabled = False
                chkLandlordCompany.Enabled = False
                txtTenantName1.Enabled = False
                txtTenantName2.Enabled = False
                txtTenantName3.Enabled = False
                txtTenantCompanyName.Enabled = False
                txtTenantNric1.Enabled = False
                txtTenantNric2.Enabled = False
                txtTenantNric3.Enabled = False
                txtTenantCompanyNo.Enabled = False
                chkTenantCompany.Enabled = False
            End If
            lblhidPropertyId.Text = ReadRow.Item("PropertyId").ToString
            'txtInvoiceNumber.Text = ReadRow.Item("InvoiceNumber").ToString
            txtOpenFileNumber.Text = ReadRow.Item("OpenFileRef").ToString
            If ReadRow.Item("ListerId").ToString = "" Then
                lblhidListerID.Text = ReadRow.Item("RListerId").ToString
            Else
                lblhidListerID.Text = ReadRow.Item("ListerId").ToString
            End If
            lblhidTransactorId.Text = ReadRow.Item("TransactorId").ToString
            'lblTransactor.Text = ReadRow.Item("Transactor").ToString
            'lblLister.Text = ReadRow.Item("Lister").ToString
            lblTransactor.Text = ReadRow.Item("TransactorInitial").ToString
            lblLister.Text = ReadRow.Item("ListerInitial").ToString
            If ReadRow.Item("ListDate").ToString = "" Then
                txtListDate.Text = ""
            Else
                txtListDate.Text = Format(ReadRow.Item("ListDate"), "dd-MMM-yyyy")
            End If
            If ReadRow.Item("TransactDate").ToString = "" Then
                lblTransactDate.Text = ""
            Else
                lblTransactDate.Text = Format(ReadRow.Item("TransactDate"), "dd-MMM-yyyy")
            End If
            If ReadRow.Item("Project").ToString = "" Then
                trProjectName.Visible = False
            Else
                trProjectName.Visible = True
                txtProjectName.Text = ReadRow.Item("Project").ToString
            End If
            txtPremiseName.Text = ReadRow.Item("Address").ToString
            '--Vendor--
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkLandlordCompanyInfo", "checkLandlordCompanyInfo();", True)
            If ReadRow.Item("LandlordType").ToString = "1" Then   'Company
                chkLandlordCompany.Checked = True
            End If
            txtLandlordCompanyName.Text = ReadRow.Item("LandlordCompany").ToString
            txtLandlordCompanyNo.Text = ReadRow.Item("LandlordCompanyNo").ToString
            txtLandlordName1.Text = ReadRow.Item("LandlordName1").ToString
            txtLandlordName2.Text = ReadRow.Item("LandlordName2").ToString
            txtLandlordName3.Text = ReadRow.Item("LandlordName3").ToString
            txtLandlordNric1.Text = ReadRow.Item("LandlordNRIC1").ToString
            txtLandlordNric2.Text = ReadRow.Item("LandlordNRIC2").ToString
            txtLandlordNric3.Text = ReadRow.Item("LandlordNRIC3").ToString

            txtLandlordContactPerson.Text = ReadRow.Item("LandlordContactPerson").ToString
            txtLandlordAddress.Text = ReadRow.Item("LandlordAddress").ToString
            txtLandlordPhone.Text = ReadRow.Item("LandlordPhone").ToString
            txtLandlordMobile.Text = ReadRow.Item("LandlordMobile").ToString
            txtLandlordFax.Text = ReadRow.Item("LandlordFax").ToString
            txtLandlordEmail.Text = ReadRow.Item("LandlordEmail").ToString
            txtLandlordViewMeetTele.Text = ReadRow.Item("LandlordViewMeetTele").ToString
            txtLandlordIncomeTaxNo.Text = ReadRow.Item("LandlordIncomeTax").ToString
            ddlLandlordRefer.SelectedValue = ReadRow.Item("LandlordReferral").ToString
            'hide vendor if select no
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkLandlordRefer", "checkLandlordRefer();", True)
            txtLandlordReferName.Text = ReadRow.Item("LandlordReferralName").ToString
            txtLandlordReferNRIC.Text = ReadRow.Item("LandlordReferralNRIC").ToString
            txtLandlordReferContact.Text = ReadRow.Item("LandlordReferralContact").ToString
            ddlLandlordReferStatus.SelectedValue = ReadRow.Item("LandlordReferralStatus").ToString
            If ReadRow.Item("LandlordReferralAmount").ToString = "" Then
                txtLandlordReferAmt.Text = "0.00"
            Else
                txtLandlordReferAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("LandlordReferralAmount"))
            End If
            '--Purchaser--
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkTenantCompanyInfo", "checkTenantCompanyInfo();", True)
            If ReadRow.Item("TenantType").ToString = "1" Then   'Company
                chkTenantCompany.Checked = True
            End If
            txtTenantCompanyName.Text = ReadRow.Item("TenantCompany").ToString
            txtTenantCompanyNo.Text = ReadRow.Item("TenantCompanyNo").ToString
            txtTenantName1.Text = ReadRow.Item("TenantName1").ToString
            txtTenantName2.Text = ReadRow.Item("TenantName2").ToString
            txtTenantName3.Text = ReadRow.Item("TenantName3").ToString
            txtTenantNric1.Text = ReadRow.Item("TenantNRIC1").ToString
            txtTenantNric2.Text = ReadRow.Item("TenantNRIC2").ToString
            txtTenantNric3.Text = ReadRow.Item("TenantNRIC3").ToString
            txtTenantContact.Text = ReadRow.Item("TenantContactPerson").ToString
            txtTenantAddress.Text = ReadRow.Item("TenantAddress").ToString
            txtTenantPhone.Text = ReadRow.Item("TenantPhone").ToString
            txtTenantMobile.Text = ReadRow.Item("TenantMobile").ToString
            txtTenantFax.Text = ReadRow.Item("TenantFax").ToString
            txtTenantEmail.Text = ReadRow.Item("TenantEmail").ToString
            txtTenantViewMeetTele.Text = ReadRow.Item("TenantViewMeetTele").ToString
            txtTenantIncomeTax.Text = ReadRow.Item("TenantIncomeTax").ToString
            ddlTenantRefer.SelectedValue = ReadRow.Item("TenantReferral").ToString
            'hide vendor if select no
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkTenantRefer", "checkTenantRefer();", True)
            txtTenantReferName.Text = ReadRow.Item("TenantReferralName").ToString
            txtTenantReferNRIC.Text = ReadRow.Item("TenantReferralNRIC").ToString
            txtTenantReferContact.Text = ReadRow.Item("TenantReferralContact").ToString
            ddlTenantReferStatus.SelectedValue = ReadRow.Item("TenantReferralStatus").ToString
            If ReadRow.Item("TenantReferralAmount").ToString = "" Then
                txtTenantReferAmt.Text = "0.00"
            Else
                txtTenantReferAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TenantReferralAmount"))
            End If
            '--Vendor Fee--
            If ReadRow.Item("AgencyFee").ToString = "" Then
                txtLandlordAgencyFee.Text = "0.00"
            Else
                txtLandlordAgencyFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("AgencyFee"))
            End If
            If ReadRow.Item("GST").ToString = "" Then
                txtLandlordGst.Text = "0.00"
            Else
                txtLandlordGst.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GST"))
            End If
            If ReadRow.Item("GSTPaidBy").ToString = "1" Then
                chkLandlordGstPaid.Checked = True
            Else
                chkLandlordGstPaid.Checked = False
            End If
            If ReadRow.Item("LandlordReferralAmtSum").ToString = "" Then
                lblLandlordReferralAmt.Text = "0.00"
            Else
                lblLandlordReferralAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("LandlordReferralAmtSum"))
            End If
            If ReadRow.Item("ListingFee").ToString = "" Then
                lblListingPercent.Text = getListingPercent(objDB)
            Else
                lblListingPercent.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListingFee"))
            End If
            If ReadRow.Item("LandlordTAFee").ToString = "" Then
                txtLandLordTAFee.Text = "0.00"
            Else
                txtLandLordTAFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("LandlordTAFee"))
            End If
            '--Purchase Fee--
            If ReadRow.Item("DisbursementFee").ToString = "" Then
                txtTenantDisbursement.Text = "0.00"
            Else
                txtTenantDisbursement.Text = String.Format("{0:#,##0.00}", ReadRow.Item("DisbursementFee"))
            End If
            If ReadRow.Item("TenantReferralAmtSum").ToString = "" Then
                lblTenantReferralAmt.Text = "0.00"
            Else
                lblTenantReferralAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TenantReferralAmtSum"))
            End If
            If ReadRow.Item("TenantTAFee").ToString = "" Then
                txtTenantTAFee.Text = "0.00"
            Else
                txtTenantTAFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TenantTAFee"))
            End If
            If ReadRow.Item("DepositMonth").ToString = "" Then
                txtTenantMonthValue.Text = "0.00"
            Else
                txtTenantMonthValue.Text = String.Format("{0:#,##0.00}", ReadRow.Item("DepositMonth"))
            End If
            If ReadRow.Item("Deposit").ToString = "" Then
                txtTenantMonthDeposit.Text = "0.00"
            Else
                txtTenantMonthDeposit.Text = String.Format("{0:#,##0.00}", ReadRow.Item("Deposit"))
            End If
            If ReadRow.Item("AdvanceMonth").ToString = "" Then
                txtTenantAdvanceValue.Text = "0.00"
            Else
                txtTenantAdvanceValue.Text = String.Format("{0:#,##0.00}", ReadRow.Item("AdvanceMonth"))
            End If
            If ReadRow.Item("Advance").ToString = "" Then
                txtTenantAdvance.Text = "0.00"
            Else
                txtTenantAdvance.Text = String.Format("{0:#,##0.00}", ReadRow.Item("Advance"))
            End If
            If ReadRow.Item("WaterElectric").ToString = "" Then
                txtTenantWaterElec.Text = "0.00"
            Else
                txtTenantWaterElec.Text = String.Format("{0:#,##0.00}", ReadRow.Item("WaterElectric"))
            End If
            If ReadRow.Item("Tel").ToString = "" Then
                txtTenantTel.Text = "0.00"
            Else
                txtTenantTel.Text = String.Format("{0:#,##0.00}", ReadRow.Item("Tel"))
            End If
            If ReadRow.Item("TransListType").ToString = "0" Then
                rbtTransactAs.ClearSelection()
            Else
                rbtTransactAs.SelectedValue = ReadRow.Item("TransListType").ToString
            End If
            If ReadRow.Item("CoBroke").ToString = "1" Then
                CoBroke.Visible = True
                lblhidCoBrokeId.Text = ReadRow.Item("CoBrokeId").ToString
                lblCoBroke.Text = ReadRow.Item("CoBrokeName").ToString
                lblhidCoBrokeAgencyName.Text = ReadRow.Item("CoBrokeAgencyName").ToString
                lblhidCoBrokePhone.Text = ReadRow.Item("CoBrokePhone").ToString
                lblhidCoBrokeMobile.Text = ReadRow.Item("CoBrokeMobile").ToString
                lblhidCoBrokeFax.Text = ReadRow.Item("CoBrokeFax").ToString
                lblhidCoBrokeEmail.Text = ReadRow.Item("CoBrokeEmail").ToString
            Else
                CoBroke.Visible = False
            End If
            txtMonthlyRental.Text = ReadRow.Item("MonthlyRental").ToString
            txtDurationOfTenancy.Text = ReadRow.Item("TenancyDuration").ToString
            ddlModeOfPayment.SelectedValue = ReadRow.Item("TenancyDurationType").ToString
            ddlUseOfPremis.SelectedValue = ReadRow.Item("PremiseUse").ToString
            txtRequisition.Text = ReadRow.Item("Requisition").ToString
            txtTerminationClause.Text = ReadRow.Item("TerminationClause").ToString
            If ReadRow.Item("TotalTA").ToString = "" Then
                lblTotalTAFee.Text = "0.00"
            Else
                lblTotalTAFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TotalTA"))
            End If
            'If ReadRow.Item("RENTA").ToString = "" Then
            '    lblRenTAFee.Text = "0.00"
            'Else
            '    lblRenTAFee.Text = ReadRow.Item("RENTA").ToString
            'End If
            If ReadRow.Item("TotalAgencyFee").ToString = "" Then
                lblTotalAgencyFee.Text = "0.00"
            Else
                lblTotalAgencyFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TotalAgencyFee"))
            End If
            If ReadRow.Item("StampDuty").ToString = "" Then
                Dim stampDutyFrom, StampDutyTo As String
                getStampDutyFromTo(objDB, stampDutyFrom, StampDutyTo)
                lblStampDuty.Text = String.Format("{0:#,##0.00}", getStampDuty(objDB, stampDutyFrom, StampDutyTo))
            Else
                lblStampDuty.Text = String.Format("{0:#,##0.00}", ReadRow.Item("StampDuty"))
            End If
            If ReadRow.Item("ListerAmt").ToString = "" Then
                lblForLister.Text = "0.00"
            Else
                lblForLister.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListerAmt"))
            End If
            If ReadRow.Item("ReferralAmt").ToString = "" Then
                lblForReferral.Text = "0.00"
            Else
                lblForReferral.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ReferralAmt"))
            End If
            If ReadRow.Item("GovAmt").ToString = "" Then
                lblForGorv.Text = "0.00"
            Else
                lblForGorv.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GovAmt"))
            End If
            If ReadRow.Item("GrossAmount").ToString = "" Then
                lblGrossAmount.Text = "0.00"
            Else
                lblGrossAmount.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GrossAmount"))
            End If
            If ReadRow.Item("ListingFee").ToString = "" Then
                lblListingPercent.Text = String.Format("{0:#,##0.00}", getListingPercent(objDB))
            Else
                lblListingPercent.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListingFee"))
            End If
            'lblForCompany.Text = ReadRow.Item("CompanyAmt").ToString
            'lblForTransactor.Text = ReadRow.Item("TransactorAmt").ToString
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "Calculation", "Calculation();", True)
        Next
    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET " & _
                                        "ListerId = @ListerId, ListDate = @ListDate, " & _
                                        "LandlordType=@LandlordType, LandlordName1=@LandlordName1, LandlordName2=@LandlordName2, LandlordName3=@LandlordName3, LandlordCompany=@LandlordCompany, " & _
                                        "LandlordNRIC1=@LandlordNRIC1, LandlordNRIC2=@LandlordNRIC2, LandlordNRIC3=@LandlordNRIC3, LandlordCompanyNo=@LandlordCompanyNo, " & _
                                        "LandlordAddress=@LandlordAddress, LandlordPhone=@LandlordPhone, LandlordMobile=@LandlordMobile, LandlordFax=@LandlordFax, " & _
                                        "LandlordEmail=@LandlordEmail, LandlordReferral=@LandlordReferral, LandlordReferralName=@LandlordReferralName, LandlordContactPerson=@LandlordContactPerson, " & _
                                        "LandlordReferralNRIC=@LandlordReferralNRIC, LandlordReferralContact=@LandlordReferralContact, LandlordReferralStatus=@LandlordReferralStatus, " & _
                                        "LandlordReferralAmount=@LandlordReferralAmount, LandlordReferralAmtSum=@LandlordReferralAmtSum, LandlordViewMeetTele=@LandlordViewMeetTele, " & _
                                        "AgencyFee=@AgencyFee, GST=@GST, GSTPaidby=@GSTPaidBy, ListingFee=@ListingFee, LandlordTAFee=@LandlordTAFee, LandlordIncomeTax=LandlordIncomeTax, " & _
                                        "TenantType=@TenantType, TenantName1=@TenantName1, TenantName2=@TenantName2, TenantName3=@TenantName3, TenantCompany=@TenantCompany, TenantNRIC1=@TenantNRIC1, " & _
                                        "TenantNRIC2=@TenantNRIC2, TenantNRIC3=@TenantNRIC3, TenantCompanyNo=@TenantCompanyNo, TenantAddress=@TenantAddress, " & _
                                        "TenantPhone=@TenantPhone, TenantMobile=@TenantMobile, TenantFax=@TenantFax, TenantEmail=@TenantEmail, TenantViewMeetTele=@TenantViewMeetTele, " & _
                                        "TenantReferral=@TenantReferral, TenantReferralName=@TenantReferralName, TenantContactPerson=@TenantContactPerson, TenantIncomeTax=@TenantIncomeTax, " & _
                                        "TenantReferralNRIC=@TenantReferralNRIC, TenantReferralContact=@TenantReferralContact, TenantReferralStatus=@TenantReferralStatus, " & _
                                        "TenantReferralAmount=@TenantReferralAmount, TenantReferralAmtSum=@TenantReferralAmtSum, DisbursementFee=@DisbursementFee, " & _
                                        "TransListType=@TransListType, Deposit=@Deposit, DepositMonth=@DepositMonth, Advance=@Advance, AdvanceMonth=@AdvanceMonth, " & _
                                        "WaterElectric=@WaterElectric, Tel=@Tel, TenantTAFee=@TenantTAFee, MonthlyRental=@MonthlyRental, TenancyDuration=@TenancyDuration, TenancyDurationType=@TenancyDurationType, " & _
                                        "Requisition=@Requisition, TerminationClause=@TerminationClause, PremiseUse=@PremiseUse, TotalTA=@TotalTA, UpdateWho=@UpdateWho, UpdateDate=@UpdateDate, " & _
                                        "TotalAgencyFee=@TotalAgencyFee, StampDuty=@StampDuty, ListerAmt=@ListerAmt, ReferralAmt=@ReferralAmt, GovAmt=@GovAmt, GrossAmount=@GrossAmount " & _
                                        "WHERE TransactionId=@TransId"
            objDB.AddParameter("ListerId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidListerID.Text))
            objDB.AddParameter("ListDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtListDate.Text, "dd-MMM-yyyy", Nothing))
            objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
            objDB.AddParameter("TransListType", Data.SqlDbType.TinyInt, CInt(rbtTransactAs.SelectedValue))
            If txtMonthlyRental.Text = "" Then
                objDB.AddParameter("MonthlyRental", Data.SqlDbType.Decimal, DBNull.Value)
            Else
                objDB.AddParameter("MonthlyRental", Data.SqlDbType.Decimal, CDbl(txtMonthlyRental.Text.Trim))
            End If
            If txtDurationOfTenancy.Text = "" Then
                objDB.AddParameter("TenancyDuration", Data.SqlDbType.Decimal, DBNull.Value)
            Else
                objDB.AddParameter("TenancyDuration", Data.SqlDbType.Decimal, CDbl(txtDurationOfTenancy.Text.Trim))
            End If
            objDB.AddParameter("TenancyDurationType", Data.SqlDbType.TinyInt, CInt(ddlModeOfPayment.SelectedValue))
            If txtRequisition.Text = "" Then
                objDB.AddParameter("Requisition", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Requisition", Data.SqlDbType.NChar, txtRequisition.Text.ToUpper.Trim)
            End If
            objDB.AddParameter("PremiseUse", Data.SqlDbType.TinyInt, CInt(ddlUseOfPremis.SelectedValue))
            If txtTerminationClause.Text = "" Then
                objDB.AddParameter("TerminationClause", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TerminationClause", Data.SqlDbType.NVarChar, txtTerminationClause.Text.ToUpper.Trim)
            End If
            If chkLandlordCompany.Checked Then
                objDB.AddParameter("LandlordType", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("LandlordName1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordName2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordName3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordCompany", Data.SqlDbType.NVarChar, txtLandlordCompanyName.Text.ToUpper.Trim)
                objDB.AddParameter("LandlordNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordCompanyNo", Data.SqlDbType.NVarChar, txtLandlordCompanyNo.Text.ToUpper.Trim)
            Else
                objDB.AddParameter("LandlordType", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("LandlordName1", Data.SqlDbType.NVarChar, txtLandlordName1.Text.ToUpper.Trim)
                objDB.AddParameter("LandlordName2", Data.SqlDbType.NVarChar, txtLandlordName2.Text.ToUpper.Trim)
                objDB.AddParameter("LandlordName3", Data.SqlDbType.NVarChar, txtLandlordName3.Text.ToUpper.Trim)
                objDB.AddParameter("LandlordCompany", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordNRIC1", Data.SqlDbType.NVarChar, txtLandlordNric1.Text.ToUpper.Trim)
                objDB.AddParameter("LandlordNRIC2", Data.SqlDbType.NVarChar, txtLandlordNric2.Text.ToUpper.Trim)
                objDB.AddParameter("LandlordNRIC3", Data.SqlDbType.NVarChar, txtLandlordNric3.Text.ToUpper.Trim)
                objDB.AddParameter("LandlordCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtLandlordContactPerson.Text = "" Then
                objDB.AddParameter("LandlordContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordContactPerson", Data.SqlDbType.NVarChar, txtLandlordContactPerson.Text.ToUpper.Trim)
            End If
            If txtLandlordAddress.Text = "" Then
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, txtLandlordAddress.Text.ToUpper.Trim)
            End If
            If txtLandlordPhone.Text = "" Then
                objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, txtLandlordPhone.Text.ToUpper.Trim)
            End If
            If txtLandlordMobile.Text = "" Then
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.ToUpper.Trim)
            End If
            If txtLandlordFax.Text = "" Then
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, txtLandlordFax.Text.ToUpper.Trim)
            End If
            If txtLandlordEmail.Text = "" Then
                objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, txtLandlordEmail.Text.ToUpper.Trim)
            End If
            If txtLandlordIncomeTaxNo.Text = "" Then
                objDB.AddParameter("LandlordIncomeTax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordIncomeTax", Data.SqlDbType.NVarChar, txtLandlordIncomeTaxNo.Text.ToUpper.Trim)
            End If
            If txtLandlordViewMeetTele.Text = "" Then
                objDB.AddParameter("LandlordViewMeetTele", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordViewMeetTele", Data.SqlDbType.NVarChar, txtLandlordViewMeetTele.Text.ToUpper.Trim)
            End If
            If ddlLandlordRefer.SelectedValue = "1" Then
                objDB.AddParameter("LandlordReferral", Data.SqlDbType.TinyInt, 1)
                If txtLandlordReferName.Text = "" Then
                    objDB.AddParameter("LandlordReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("LandlordReferralName", Data.SqlDbType.NVarChar, txtLandlordReferName.Text.ToUpper.Trim)
                End If
                If txtLandlordReferNRIC.Text = "" Then
                    objDB.AddParameter("LandlordReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("LandlordReferralNRIC", Data.SqlDbType.NVarChar, txtLandlordReferNRIC.Text.ToUpper.Trim)
                End If
                If txtLandlordReferContact.Text = "" Then
                    objDB.AddParameter("LandlordReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("LandlordReferralContact", Data.SqlDbType.NVarChar, txtLandlordReferContact.Text.ToUpper.Trim)
                End If
                objDB.AddParameter("LandlordReferralStatus", Data.SqlDbType.TinyInt, ddlLandlordReferStatus.SelectedValue)
                If txtLandlordReferAmt.Text = "" Then
                    objDB.AddParameter("LandlordReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                Else
                    objDB.AddParameter("LandlordReferralAmount", Data.SqlDbType.Decimal, CDbl(txtLandlordReferAmt.Text.Trim))
                End If
            Else
                objDB.AddParameter("LandlordReferral", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("LandlordReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("LandlordReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                objDB.AddParameter("LandlordReferralStatus", Data.SqlDbType.TinyInt, ddlLandlordReferStatus.SelectedValue)
            End If
            If chkTenantCompany.Checked Then
                objDB.AddParameter("TenantType", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("TenantName1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantName2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantName3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantCompany", Data.SqlDbType.NVarChar, txtTenantCompanyName.Text.ToUpper.Trim)
                objDB.AddParameter("TenantNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantCompanyNo", Data.SqlDbType.NVarChar, txtTenantCompanyNo.Text.ToUpper.Trim)
            Else
                objDB.AddParameter("TenantType", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("TenantName1", Data.SqlDbType.NVarChar, txtTenantName1.Text.ToUpper.Trim)
                objDB.AddParameter("TenantName2", Data.SqlDbType.NVarChar, txtTenantName2.Text.ToUpper.Trim)
                objDB.AddParameter("TenantName3", Data.SqlDbType.NVarChar, txtTenantName3.Text.ToUpper.Trim)
                objDB.AddParameter("TenantCompany", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantNRIC1", Data.SqlDbType.NVarChar, txtTenantNric1.Text.ToUpper.Trim)
                objDB.AddParameter("TenantNRIC2", Data.SqlDbType.NVarChar, txtTenantNric2.Text.ToUpper.Trim)
                objDB.AddParameter("TenantNRIC3", Data.SqlDbType.NVarChar, txtTenantNric3.Text.ToUpper.Trim)
                objDB.AddParameter("TenantCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtTenantContact.Text = "" Then
                objDB.AddParameter("TenantContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantContactPerson", Data.SqlDbType.NVarChar, txtTenantContact.Text.ToUpper.Trim)
            End If
            If txtTenantAddress.Text = "" Then
                objDB.AddParameter("TenantAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantAddress", Data.SqlDbType.NVarChar, txtTenantAddress.Text.ToUpper.Trim)
            End If
            If txtTenantPhone.Text = "" Then
                objDB.AddParameter("TenantPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantPhone", Data.SqlDbType.NVarChar, txtTenantPhone.Text.ToUpper.Trim)
            End If
            If txtTenantMobile.Text = "" Then
                objDB.AddParameter("TenantMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantMobile", Data.SqlDbType.NVarChar, txtTenantMobile.Text.ToUpper.Trim)
            End If
            If txtTenantFax.Text = "" Then
                objDB.AddParameter("TenantFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantFax", Data.SqlDbType.NVarChar, txtTenantFax.Text.ToUpper.Trim)
            End If
            If txtTenantEmail.Text = "" Then
                objDB.AddParameter("TenantEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantEmail", Data.SqlDbType.NVarChar, txtTenantEmail.Text.ToUpper.Trim)
            End If
            If txtTenantIncomeTax.Text = "" Then
                objDB.AddParameter("TenantIncomeTax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantIncomeTax", Data.SqlDbType.NVarChar, txtTenantIncomeTax.Text.ToUpper.Trim)
            End If
            If txtTenantViewMeetTele.Text = "" Then
                objDB.AddParameter("TenantViewMeetTele", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantViewMeetTele", Data.SqlDbType.NVarChar, txtTenantViewMeetTele.Text.ToUpper.Trim)
            End If
            If ddlTenantRefer.SelectedValue = "1" Then
                objDB.AddParameter("TenantReferral", Data.SqlDbType.TinyInt, 1)
                If txtTenantReferName.Text = "" Then
                    objDB.AddParameter("TenantReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("TenantReferralName", Data.SqlDbType.NVarChar, txtTenantReferName.Text.ToUpper.Trim)
                End If
                If txtTenantReferNRIC.Text = "" Then
                    objDB.AddParameter("TenantReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("TenantReferralNRIC", Data.SqlDbType.NVarChar, txtTenantReferNRIC.Text.ToUpper.Trim)
                End If
                If txtTenantReferContact.Text = "" Then
                    objDB.AddParameter("TenantReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("TenantReferralContact", Data.SqlDbType.NVarChar, txtTenantReferContact.Text.ToUpper.Trim)
                End If
                objDB.AddParameter("TenantReferralStatus", Data.SqlDbType.TinyInt, ddlTenantReferStatus.SelectedValue)
                If txtTenantReferAmt.Text = "" Then
                    objDB.AddParameter("TenantReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                Else
                    objDB.AddParameter("TenantReferralAmount", Data.SqlDbType.Decimal, CDbl(txtTenantReferAmt.Text.Trim))
                End If
            Else
                objDB.AddParameter("TenantReferral", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("TenantReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("TenantReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                objDB.AddParameter("TenantReferralStatus", Data.SqlDbType.TinyInt, ddlTenantReferStatus.SelectedValue)
            End If
            'Fee
            If txtLandlordAgencyFee.Text = "" Then
                objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(txtLandlordAgencyFee.Text.Trim))
            End If
            If txtLandLordTAFee.Text = "" Then
                objDB.AddParameter("LandlordTAFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("LandlordTAFee", Data.SqlDbType.Decimal, CDbl(txtLandLordTAFee.Text.Trim))
            End If
            If txtLandlordGst.Text = "" Then
                objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(txtLandlordGst.Text.Trim))
            End If
            If chkLandlordGstPaid.Checked Then
                objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 0)
            End If
            If lblListingPercent.Text = "" Then
                objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(lblListingPercent.Text.Trim))
            End If
            If lblLandlordReferralAmt.Text = "" Then
                objDB.AddParameter("LandlordReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("LandlordReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblLandlordReferralAmt.Text.Trim))
            End If
            If txtTenantDisbursement.Text = "" Then
                objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(txtTenantDisbursement.Text.Trim))
            End If
            If lblTenantReferralAmt.Text = "" Then
                objDB.AddParameter("TenantReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("TenantReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblTenantReferralAmt.Text.Trim))
            End If
            If txtTenantMonthValue.Text = "" Then
                objDB.AddParameter("DepositMonth", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("DepositMonth", Data.SqlDbType.Decimal, CDbl(txtTenantMonthValue.Text.Trim))
            End If
            If txtTenantMonthDeposit.Text = "" Then
                objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(txtTenantMonthDeposit.Text.Trim))
            End If
            If txtTenantAdvance.Text = "" Then
                objDB.AddParameter("Advance", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("Advance", Data.SqlDbType.Decimal, CDbl(txtTenantAdvance.Text.Trim))
            End If
            If txtTenantAdvanceValue.Text = "" Then
                objDB.AddParameter("AdvanceMonth", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("AdvanceMonth", Data.SqlDbType.Decimal, CDbl(txtTenantAdvanceValue.Text.Trim))
            End If
            If txtTenantWaterElec.Text = "" Then
                objDB.AddParameter("WaterElectric", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("WaterElectric", Data.SqlDbType.Decimal, CDbl(txtTenantWaterElec.Text.Trim))
            End If
            If txtTenantTel.Text = "" Then
                objDB.AddParameter("Tel", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("Tel", Data.SqlDbType.Decimal, CDbl(txtTenantTel.Text.Trim))
            End If
            If txtTenantTAFee.Text = "" Then
                objDB.AddParameter("TenantTAFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("TenantTAFee", Data.SqlDbType.Decimal, CDbl(txtTenantTAFee.Text.Trim))
            End If
            If lblTotalAgencyFee.Text = "" Then
                objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(lblTotalAgencyFee.Text.Trim))
            End If
            If lblForLister.Text = "" Then
                objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(lblForLister.Text.Trim))
            End If
            If lblForReferral.Text = "" Then
                objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(lblForReferral.Text.Trim))
            End If
            If lblForGorv.Text = "" Then
                objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(lblForGorv.Text.Trim))
            End If
            If lblGrossAmount.Text = "" Then
                objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(lblGrossAmount.Text.Trim))
            End If
            If lblTotalTAFee.Text = "" Then
                objDB.AddParameter("TotalTA", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("TotalTA", Data.SqlDbType.Decimal, CDbl(lblTotalTAFee.Text.Trim))
            End If
            If lblStampDuty.Text = "" Then
                objDB.AddParameter("StampDuty", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("StampDuty", Data.SqlDbType.Decimal, CDbl(lblStampDuty.Text.Trim))
            End If
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
            'If lblRenTAFee.Text = "" Then
            '    objDB.AddParameter("RENTA", Data.SqlDbType.Decimal, CDbl(0.0))
            'Else
            '    objDB.AddParameter("RENTA", Data.SqlDbType.Decimal, CDbl(lblRenTAFee.Text.Trim))
            'End If
            objDB.ExecuteQuery()
            Dim strOpenFileRef As String = String.Empty
            If txtOpenFileNumber.Text = "" Then
                getOpenFormatNumber(objDB, strOpenFileRef, New Guid(lblhidTransactorId.Text.Trim), New Guid(lblhidListerID.Text.Trim), "R", New Guid(lblStaffUID.Text))
                objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, strOpenFileRef)
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
                objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET " & _
                                    "OpenFileRef=@OpenFileRef, Status=@Status " & _
                                    "WHERE TransactionId=@TransId"
            Else
                strOpenFileRef = txtOpenFileNumber.Text.ToUpper.Trim
                objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, txtOpenFileNumber.Text.ToUpper.Trim)
                objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
                objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET " & _
                                    "OpenFileRef=@OpenFileRef " & _
                                    "WHERE TransactionId=@TransId"
            End If
            objDB.ExecuteQuery()
            objDB.ClearParameter()
            objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, strOpenFileRef)
            InsertTrans_Old(objDB)
            objDB.DbTransCommit()
            objDB.CloseConnection()
            Session.Add("entry", txtPremiseName.Text.Trim)
            Response.Redirect("Translist.aspx", False)
        Catch ex As Exception
            objDB.DbTransRollback()
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try

    End Sub

    Protected Sub rbtTransactAs_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbtTransactAs.SelectedIndexChanged
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        Select Case rbtTransactAs.SelectedValue
            Case "1"  '--RR
                objDB.dbVariable.SQLString = "SELECT RRCreateDate as CreateDate, RListerId as ListerId, l.Name as Lister FROM AW_Property p INNER JOIN AW_RentTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.RListerId = l.StaffId WHERE TransactionId = @TransId"
            Case "2" '--RC
                objDB.dbVariable.SQLString = "SELECT RCCreateDate as CreateDate, RListerId as ListerId, l.Name as Lister FROM AW_Property p INNER JOIN AW_RentTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.RListerId = l.StaffId WHERE TransactionId = @TransId"
            Case "3" '--RL
                objDB.dbVariable.SQLString = "SELECT RLCreateDate as CreateDate, RListerId as ListerId, l.Name as Lister FROM AW_Property p INNER JOIN AW_RentTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.RListerId = l.StaffId WHERE TransactionId = @TransId"
            Case "4" '--RI
                objDB.dbVariable.SQLString = "SELECT RICreateDate as CreateDate, RListerId as ListerId, l.Name as Lister FROM AW_Property p INNER JOIN AW_RentTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.RListerId = l.StaffId WHERE TransactionId = @TransId"
        End Select
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text.Trim))
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each row As Data.DataRow In TempDT.Rows
            txtListDate.Text = Format(row.Item("CreateDate"), "dd-MMM-yyyy")
            lblLister.Text = row.Item("Lister").ToString
            lblhidListerID.Text = row.Item("ListerId").ToString
        Next
    End Sub

    Private Function getListingPercent(ByRef ObjDB As Database) As String
        Dim ListingPercentDT As New Data.DataTable
        Dim ListingPercent As String = "0.00"

        ObjDB.dbVariable.SQLString = "SELECT ListingPercent FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidListerID.Text.Trim))
        ObjDB.FillData(ListingPercentDT, "ListingPercent", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In ListingPercentDT.Rows
            If ReadRow.Item("ListingPercent").ToString = "" Then
                ListingPercent = "0.00"
            Else
                ListingPercent = ReadRow.Item("ListingPercent").ToString
            End If
        Next
        Return ListingPercent
    End Function

    Private Function getStampDuty(ByRef ObjDB As Database, ByVal sdFrom As String, ByVal sdTo As String) As String
        Dim StampDutyDT As New Data.DataTable
        Dim StampDuty As String = "0.00"
        Dim MonthlyRental As Decimal = 0
        Dim dyear As Decimal = 0
        Dim yearType As Integer = 0

        If txtMonthlyRental.Text = "" Then
            MonthlyRental = 0
        Else
            MonthlyRental = CDbl(txtMonthlyRental.Text)
        End If

        If ddlModeOfPayment.SelectedValue = "0" Then
            If txtDurationOfTenancy.Text = "" Then
                dyear = 0
            Else
                dyear = CDbl(txtDurationOfTenancy.Text.Trim)
            End If
        Else
            dyear = 1
        End If

        If dyear <= CDbl(sdFrom) Then
            yearType = 1
        ElseIf dyear > CDbl(sdTo) Then
            yearType = 2
        Else
            'Error
        End If

        ObjDB.dbVariable.SQLString = "SELECT StampDuty FROM AW_StampDuty WHERE AmountFrom<=@MonthlyRental AND AmountTo>@MonthlyRental " & _
                                    "AND StampDutyType=@StampDutyType "
        ObjDB.AddParameter("MonthlyRental", Data.SqlDbType.Decimal, MonthlyRental)
        ObjDB.AddParameter("StampDutyType", Data.SqlDbType.TinyInt, yearType)
        ObjDB.FillData(StampDutyDT, "StampDuty", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In StampDutyDT.Rows
            If ReadRow.Item("StampDuty").ToString = "" Then
                StampDuty = "0.00"
            Else
                StampDuty = ReadRow.Item("StampDuty").ToString
                'StampDuty = CDbl(StampDuty) * 2
                'Edited by minginn @ 16/11/2011 - to handle the stampduty from purchaser side and landlord will forever RM10
                StampDuty = CDbl(StampDuty) + 10
            End If
        Next
        Return StampDuty
    End Function

    ''' <summary>
    ''' This function will Get All the Formatted Number
    ''' </summary>
    ''' <param name="ObjDB">The Database object used</param>
    ''' <param name="OpenFormat">The String variable of the Open Number</param>
    ''' <param name="TransactorUid">The GUID variable of the Transactor</param>
    ''' <param name="ListerUid">The GUID variable of the Lister</param>
    ''' <param name="ListType">Please pass in only R or S</param>
    ''' <returns>It Returns nothing but it uses the ByRef</returns>
    ''' <remarks></remarks>
    Private Function getOpenFormatNumber(ByRef ObjDB As Database, ByRef OpenFormat As String, ByVal TransactorUid As Guid, ByVal ListerUid As Guid, ByVal ListType As String, ByVal LoginUid As Guid) As Integer

        Dim InvoiceDT As New Data.DataTable
        Dim ListerDT As New Data.DataTable
        Dim TransactorDT As New Data.DataTable
        Dim RunningNoDt As New Data.DataTable
        Dim OpenFileRunningNo As Integer = 0
        Dim TransactorInitial As String = ""
        Dim ListerInitial As String = ""
        Dim ListerName As String = ""
        Dim CompanyName As String = ""
        Dim CompanyInitial As String = ""
        'Added by : Daniel
        'Date : 19-July-2011
        'Purpose : To include Login Id
        Dim LoginInitialDT As New Data.DataTable
        Dim LoginInital As String = ""


        'Get All Information Before Proceesing
        'Get Transactor Initial
        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, TransactorUid)
        ObjDB.FillData(TransactorDT, "Transactor", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In TransactorDT.Rows
            TransactorInitial = ReadRow.Item("Initial").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, LoginUid)
        ObjDB.FillData(LoginInitialDT, "LoginInitial", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In LoginInitialDT.Rows
            LoginInital = ReadRow.Item("Initial").ToString
        Next


        ObjDB.dbVariable.SQLString = "SELECT Initial,Name FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, ListerUid)
        ObjDB.FillData(ListerDT, "Lister", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In ListerDT.Rows
            ListerInitial = ReadRow.Item("Initial").ToString
            ListerName = ReadRow.Item("Name").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT CurrentNo,RunType FROM aw_runningNo WITH (TABLOCKX) WHERE RunType='O' "
        ObjDB.FillData(RunningNoDt, "RunningNo", Database.SQLCommandType.NormalString)

        'Begin Updating Current Running No
        ObjDB.dbVariable.SQLString = "UPDATE aw_runningNo SET CurrentNo=CurrentNo+1 WHERE RunType='O'"
        ObjDB.ExecuteQuery()

        For Each ReadRow As Data.DataRow In RunningNoDt.Rows
            If ReadRow.Item("RunType").ToString = "O" Then
                OpenFileRunningNo = ReadRow.Item("CurrentNo")
            End If
        Next

        ObjDB.dbVariable.SQLString = "SELECT OpenFormat,CompanyName,CompanyInitial FROM AW_Setting"
        ObjDB.FillData(InvoiceDT, "OpenFormat", Database.SQLCommandType.NormalString)

        Dim OpenFormatString As String()

        For Each ReadRow As Data.DataRow In InvoiceDT.Rows
            OpenFormatString = ReadRow.Item("OpenFormat").ToString.Split(";")
            CompanyInitial = ReadRow.Item("CompanyInitial").ToString
            CompanyName = ReadRow.Item("CompanyName").ToString
        Next


        Dim strOpenFormat As String = String.Empty
        If OpenFormatString.Count > 0 Then
            For Each Format As String In OpenFormatString
                Select Case Format.Trim
                    Case "tInit"
                        strOpenFormat = strOpenFormat & TransactorInitial
                    Case "lName"
                        strOpenFormat = strOpenFormat & ListerName
                    Case "lInit"
                        strOpenFormat = strOpenFormat & ListerInitial
                    Case "cName"
                        strOpenFormat = strOpenFormat & CompanyName
                    Case "cInit"
                        strOpenFormat = strOpenFormat & CompanyInitial
                    Case "rNumber"
                        strOpenFormat = strOpenFormat & OpenFileRunningNo
                    Case "dDate1"
                        strOpenFormat = strOpenFormat & Now.ToString("dd/MM")
                    Case "dDate2"
                        strOpenFormat = strOpenFormat & Now.ToString("dd/MM/yyyy")
                    Case "LoginInit"
                        strOpenFormat = strOpenFormat & LoginInital
                    Case "lType"
                        If ListType = "S" Then
                            strOpenFormat = strOpenFormat & "S"
                        Else
                            strOpenFormat = strOpenFormat & "R"
                        End If
                    Case "dash"
                        strOpenFormat = strOpenFormat & "-"
                    Case "slash"
                        strOpenFormat = strOpenFormat & "/"
                    Case "empty"
                        strOpenFormat = strOpenFormat & ""
                End Select

            Next
        End If

        OpenFormat = strOpenFormat
        Return 0
    End Function

    Protected Sub btnStampDuty_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStampDuty.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()
        Dim StampDutyFrom As String = String.Empty
        Dim StampDutyTo As String = String.Empty
        getStampDutyFromTo(objDB, StampDutyFrom, StampDutyTo)
        lblStampDuty.Text = getStampDuty(objDB, StampDutyFrom, StampDutyTo)
        objDB.CloseConnection()
        'Calculation
        Calculation()
    End Sub

    Private Sub getStampDutyFromTo(ByVal objDB As Database, ByRef StampDutyFrom As String, ByRef StampDutyTo As String)
        Dim TempDT As New Data.DataTable
        objDB.dbVariable.SQLString = "SELECT StampDutyFrom, StampDutyTo FROM AW_Setting"
        objDB.FillData(TempDT, "AW_StampDuty", Database.SQLCommandType.NormalString)
        If TempDT.Rows.Count > 0 Then
            StampDutyFrom = TempDT.Rows(0).Item("StampDutyFrom").ToString
            StampDutyTo = TempDT.Rows(0).Item("StampDutyTo").ToString
        End If
    End Sub

    Protected Sub btnGetListingFee_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetListingFee.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()
        lblListingPercent.Text = getListingPercent(objDB)
        objDB.CloseConnection()
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "Calculation", "Calculation();", True)
        'Calculation
        Calculation()
    End Sub

    Private Sub Calculation()
        Dim landlordRefferalAmt, TenantReferralAmt As Decimal
        Dim GST, TotalAgencyFee, LandlordAgencyFee As Decimal
        Dim Referral, Lister, TA, StampDuty, GrossAmount As Decimal
        'Referral Summary
        If ddlLandlordReferStatus.SelectedValue = "0" And ddlTenantReferStatus.SelectedValue = "1" Then
            landlordRefferalAmt = CDbl(txtLandlordReferAmt.Text) + CDbl(txtTenantReferAmt.Text)
            TenantReferralAmt = 0
            lblLandlordReferralAmt.Text = String.Format("{0:#,##0.00}", landlordRefferalAmt)
            lblTenantReferralAmt.Text = String.Format("{0:#,##0.00}", TenantReferralAmt)
        ElseIf ddlLandlordReferStatus.SelectedValue = "1" And ddlTenantReferStatus.SelectedValue = "0" Then
            TenantReferralAmt = CDbl(txtLandlordReferAmt.Text) + CDbl(txtTenantReferAmt.Text)
            landlordRefferalAmt = 0
            lblLandlordReferralAmt.Text = String.Format("{0:#,##0.00}", landlordRefferalAmt)
            lblTenantReferralAmt.Text = String.Format("{0:#,##0.00}", TenantReferralAmt)
        ElseIf ddlLandlordReferStatus.SelectedValue = "1" And ddlTenantReferStatus.SelectedValue = "1" Then
            TenantReferralAmt = CDbl(txtLandlordReferAmt.Text)
            landlordRefferalAmt = CDbl(txtTenantReferAmt.Text)
            lblLandlordReferralAmt.Text = String.Format("{0:#,##0.00}", landlordRefferalAmt)
            lblTenantReferralAmt.Text = String.Format("{0:#,##0.00}", TenantReferralAmt)
        Else
            landlordRefferalAmt = CDbl(txtLandlordReferAmt.Text)
            TenantReferralAmt = CDbl(txtTenantReferAmt.Text)
            lblLandlordReferralAmt.Text = String.Format("{0:#,##0.00}", landlordRefferalAmt)
            lblTenantReferralAmt.Text = String.Format("{0:#,##0.00}", TenantReferralAmt)
        End If
        'For Gov       
        GST = (CDbl(txtLandlordGst.Text) / 100) * CDbl(txtLandlordAgencyFee.Text)
        lblForGorv.Text = String.Format("{0:#,##0.00}", GST)
        If chkLandlordGstPaid.Checked Then
            TotalAgencyFee = CDbl(txtLandlordAgencyFee.Text) + CDbl(txtTenantDisbursement.Text)
            lblTotalAgencyFee.Text = String.Format("{0:#,##0.00}", TotalAgencyFee)
        Else
            TotalAgencyFee = CDbl(txtLandlordAgencyFee.Text) + CDbl(txtTenantDisbursement.Text) - CDbl(GST)
            lblTotalAgencyFee.Text = String.Format("{0:#,##0.00}", TotalAgencyFee)
        End If
        Referral = landlordRefferalAmt + TenantReferralAmt
        lblForReferral.Text = String.Format("{0:#,##0.00}", Referral)
        'For Lister
        'edtited by minginn @ 16/11/2011 - To only take landlord AgencyFee and landlord Referrral in calculation of lister fee
        'Lister = (TotalAgencyFee - Referral) * (CDbl(lblListingPercent.Text) / 100)
        'lblForLister.Text = String.Format("{0:#,##0.00}", Lister)
        If chkLandlordGstPaid.Checked Then
            LandlordAgencyFee = CDbl(txtLandlordAgencyFee.Text)
        Else
            LandlordAgencyFee = CDbl(txtLandlordAgencyFee.Text) - CDbl(GST)
        End If
        Lister = (LandlordAgencyFee - landlordRefferalAmt) * (CDbl(lblListingPercent.Text) / 100)
        lblForLister.Text = String.Format("{0:#,##0.00}", Lister)
        'TA
        TA = CDbl(txtLandLordTAFee.Text) + CDbl(txtTenantTAFee.Text)
        lblTotalTAFee.Text = String.Format("{0:#,##0.00}", TA)
        'StampDuty
        StampDuty = CDbl(lblStampDuty.Text)
        'Gross Amount
        GrossAmount = TotalAgencyFee + TA - Referral
        lblGrossAmount.Text = String.Format("{0:#,##0.00}", GrossAmount)
    End Sub

    Private Sub InsertUpdateContactLandlord(ByRef objDB As Database)
        If txtLandlordMobile.Text <> String.Empty Then
            Dim strSQLCont As String = String.Empty
            Dim TempDT As New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT ContactId, Mobile FROM AW_Contact WHERE Mobile=@Mobile AND StatusDelete=0"
            objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.Trim.ToUpper)
            objDB.FillData(TempDT, "AW_Contact", Database.SQLCommandType.NormalString)
            If TempDT.Rows.Count > 0 Then
                'Update
                objDB.dbVariable.SQLString = "UPDATE AW_Contact SET ProspectiveType=@ProspectiveType, Name=@Name, " & _
                                            "Mobile=@Mobile" & strSQLCont & " WHERE Mobile=@Mobile"
                If txtLandlordPhone.Text <> String.Empty Then
                    strSQLCont += ", Phone=@Phone"
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtLandlordPhone.Text.Trim.ToUpper)
                End If
                If txtLandlordFax.Text <> String.Empty Then
                    strSQLCont += ", Fax=@Fax"
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtLandlordFax.Text.Trim.ToUpper)
                End If
                If txtLandlordEmail.Text <> String.Empty Then
                    strSQLCont += ", Email=@Email"
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtLandlordEmail.Text.Trim.ToUpper)
                End If
                If txtLandlordAddress.Text <> String.Empty Then
                    strSQLCont += ", Address=@Address"
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtLandlordAddress.Text.Trim.ToUpper)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 4)
                objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtLandlordContactPerson.Text.Trim.ToUpper)
                objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.Trim.ToUpper)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            Else
                'Insert
                objDB.dbVariable.SQLString = "INSERT INTO AW_Contact(ContactId,Name, ProspectiveType, Mobile, Phone, " & _
                "Fax, Email, Address, CreateDate, StatusDelete) Values(@ContactId, @Name, @ProspectiveType, @Mobile, " & _
                "@Phone, @Fax, @Email, @Address, @CreateDate, @StatusDelete) "
                objDB.AddParameter("ContactId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
                If txtLandlordPhone.Text <> String.Empty Then
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtLandlordPhone.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordFax.Text <> String.Empty Then
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtLandlordFax.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordEmail.Text <> String.Empty Then
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtLandlordEmail.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordAddress.Text <> String.Empty Then
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtLandlordAddress.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 4)
                If txtLandlordContactPerson.Text <> String.Empty Then
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtLandlordContactPerson.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtLandlordMobile.Text <> String.Empty Then
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            End If
        End If
    End Sub

    Private Sub InsertUpdateContactTenant(ByRef objDB As Database)
        If txtTenantMobile.Text <> String.Empty Then
            Dim strSQLCont As String = String.Empty
            Dim TempDT As New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT ContactId, Mobile FROM AW_Contact WHERE Mobile=@Mobile AND StatusDelete=0"
            objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtTenantMobile.Text.Trim.ToUpper)
            objDB.FillData(TempDT, "AW_Contact", Database.SQLCommandType.NormalString)
            If TempDT.Rows.Count > 0 Then
                'Update
                objDB.dbVariable.SQLString = "UPDATE AW_Contact SET ProspectiveType=@ProspectiveType, Name=@Name, " & _
                                            "Mobile=@Mobile" & strSQLCont & " WHERE Mobile=@Mobile"
                If txtTenantPhone.Text <> String.Empty Then
                    strSQLCont += ", Phone=@Phone"
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtTenantPhone.Text.Trim.ToUpper)
                End If
                If txtTenantFax.Text <> String.Empty Then
                    strSQLCont += ", Fax=@Fax"
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtTenantFax.Text.Trim.ToUpper)
                End If
                If txtTenantEmail.Text <> String.Empty Then
                    strSQLCont += ", Email=@Email"
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtTenantEmail.Text.Trim.ToUpper)
                End If
                If txtTenantAddress.Text <> String.Empty Then
                    strSQLCont += ", Address=@Address"
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtTenantAddress.Text.Trim.ToUpper)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 2)
                objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtTenantContact.Text.Trim.ToUpper)
                objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtTenantMobile.Text.Trim.ToUpper)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            Else
                'Insert
                objDB.dbVariable.SQLString = "INSERT INTO AW_Contact(ContactId,Name, ProspectiveType, Mobile, Phone, " & _
                "Fax, Email, Address, CreateDate, StatusDelete) Values(@ContactId, @Name, @ProspectiveType, @Mobile, " & _
                "@Phone, @Fax, @Email, @Address, @CreateDate, @StatusDelete) "
                objDB.AddParameter("ContactId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
                If txtTenantPhone.Text <> String.Empty Then
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtTenantPhone.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtTenantFax.Text <> String.Empty Then
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtTenantFax.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtTenantEmail.Text <> String.Empty Then
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtTenantEmail.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtTenantAddress.Text <> String.Empty Then
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtTenantAddress.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 2)
                If txtTenantContact.Text <> String.Empty Then
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtTenantContact.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtTenantMobile.Text <> String.Empty Then
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtTenantMobile.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            End If
        End If
    End Sub

    Private Sub InsertTrans_Old(ByVal objDB As Database)
        Dim OId As Guid
        If Not Session("Oid") Is Nothing Then
            OId = New Guid(Session("Oid").ToString)
            Session.Remove("Oid")
            'update
            objDB.dbVariable.SQLString = "UPDATE " + AppSettings("logdatasource").ToString() + ".dbo.AW_RentTransaction SET " & _
                                        "ListerId = @ListerId, ListDate = @ListDate, OpenFileRef=@OpenFileRef, Status=@Status, " & _
                                        "LandlordType=@LandlordType, LandlordName1=@LandlordName1, LandlordName2=@LandlordName2, LandlordName3=@LandlordName3, LandlordCompany=@LandlordCompany, " & _
                                        "LandlordNRIC1=@LandlordNRIC1, LandlordNRIC2=@LandlordNRIC2, LandlordNRIC3=@LandlordNRIC3, LandlordCompanyNo=@LandlordCompanyNo, " & _
                                        "LandlordAddress=@LandlordAddress, LandlordPhone=@LandlordPhone, LandlordMobile=@LandlordMobile, LandlordFax=@LandlordFax, " & _
                                        "LandlordEmail=@LandlordEmail, LandlordReferral=@LandlordReferral, LandlordReferralName=@LandlordReferralName, LandlordContactPerson=@LandlordContactPerson, " & _
                                        "LandlordReferralNRIC=@LandlordReferralNRIC, LandlordReferralContact=@LandlordReferralContact, LandlordReferralStatus=@LandlordReferralStatus, " & _
                                        "LandlordReferralAmount=@LandlordReferralAmount, LandlordReferralAmtSum=@LandlordReferralAmtSum, LandlordIncomeTax=@LandlordIncomeTax, " & _
                                        "AgencyFee=@AgencyFee, GST=@GST, GSTPaidby=@GSTPaidBy, ListingFee=@ListingFee, LandlordTAFee=@LandlordTAFee, LandlordViewMeetTele=@LandlordViewMeetTele, " & _
                                        "TenantType=@TenantType, TenantName1=@TenantName1, TenantName2=@TenantName2, TenantName3=@TenantName3, TenantCompany=@TenantCompany, TenantNRIC1=@TenantNRIC1, " & _
                                        "TenantNRIC2=@TenantNRIC2, TenantNRIC3=@TenantNRIC3, TenantCompanyNo=@TenantCompanyNo, TenantAddress=@TenantAddress, " & _
                                        "TenantPhone=@TenantPhone, TenantMobile=@TenantMobile, TenantFax=@TenantFax, TenantEmail=@TenantEmail, TenantIncomeTax=@TenantIncomeTax, " & _
                                        "TenantReferral=@TenantReferral, TenantReferralName=@TenantReferralName, TenantContactPerson=@TenantContactPerson, TenantViewMeetTele=@TenantViewMeetTele, " & _
                                        "TenantReferralNRIC=@TenantReferralNRIC, TenantReferralContact=@TenantReferralContact, TenantReferralStatus=@TenantReferralStatus, " & _
                                        "TenantReferralAmount=@TenantReferralAmount, TenantReferralAmtSum=@TenantReferralAmtSum, DisbursementFee=@DisbursementFee, " & _
                                        "TransListType=@TransListType, Deposit=@Deposit, DepositMonth=@DepositMonth, Advance=@Advance, AdvanceMonth=@AdvanceMonth, " & _
                                        "WaterElectric=@WaterElectric, Tel=@Tel, TenantTAFee=@TenantTAFee, MonthlyRental=@MonthlyRental, TenancyDuration=@TenancyDuration, TenancyDurationType=@TenancyDurationType, " & _
                                        "Requisition=@Requisition, TerminationClause=@TerminationClause, PremiseUse=@PremiseUse, TotalTA=@TotalTA, " & _
                                        "TotalAgencyFee=@TotalAgencyFee, StampDuty=@StampDuty, ListerAmt=@ListerAmt, ReferralAmt=@ReferralAmt, GovAmt=@GovAmt, GrossAmount=@GrossAmount " & _
                                        "WHERE OId=@OId"
            objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 1)
        Else
            OId = Guid.NewGuid
            'insert
            objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_RentTransaction (OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                                        "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                                        "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                                        "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                                        "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                                        "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                                        "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                                        "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                                        "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                                        "TerminationClause, PremiseUse, CreateDate, UpdateDate, UpdateWho, Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                                        "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                                        "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                                        "UndoGST, UndoGSTPaidBy, UndoListerAmt) SELECT @OId, TransactionId, PropertyId, InvoiceNumber, @OpenFileRef, CloseFileRef, @ListerId, @ListDate, " & _
                                        "@LandlordType, @LandlordName1, @LandlordName2, @LandlordName3, @LandlordCompany, @LandlordNRIC1, @LandlordNRIC2, @LandlordNRIC3, @LandlordCompanyNo, " & _
                                        "@LandlordContactPerson, @LandlordAddress, @LandlordPhone, @LandlordMobile, @LandlordFax, @LandlordEmail, @LandlordViewMeetTele, @LandlordIncomeTax, " & _
                                        "@LandlordReferral, @LandlordReferralName, @LandlordReferralNRIC, @LandlordReferralContact, @LandlordReferralStatus, @LandlordReferralAmount, " & _
                                        "@LandlordReferralAmtSum, @AgencyFee, @GST, @GSTPaidBy, @ListingFee, @LandlordTAFee, @TenantType, @TenantName1, @TenantName2, @TenantName3, @TenantCompany, " & _
                                        "@TenantNRIC1, @TenantNRIC2, @TenantNRIC3, @TenantCompanyNo, @TenantContactPerson, @TenantAddress, @TenantPhone, @TenantMobile, @TenantFax, @TenantEmail, " & _
                                        "@TenantViewMeetTele, @TenantIncomeTax, @TenantReferral, @TenantReferralName, @TenantReferralNRIC, @TenantReferralContact, @TenantReferralStatus, " & _
                                        "@TenantReferralAmount, @TenantReferralAmtSum, @DisbursementFee, @Deposit, @DepositMonth, @Advance, @AdvanceMonth, @WaterElectric, @Tel, @TenantTAFee, " & _
                                        "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, @TransListType, @MonthlyRental, @TenancyDuration, @TenancyDurationType, @Requisition, " & _
                                        "@TerminationClause, @PremiseUse, @CreateDateOLD, @UpdateDateOLD, @UpdateWhoOLD, Status, Renewed, @TotalTA, @TotalAgencyFee, @StampDuty, @ListerAmt, @ReferralAmt, " & _
                                        "@GovAmt, @GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                                        "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                                        "UndoGST, UndoGSTPaidBy, UndoListerAmt FROM AW_RentTransaction WHERE TransactionId=@TransId"
            objDB.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        End If

        objDB.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, OId)

        objDB.AddParameter("ListerId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidListerID.Text))
        objDB.AddParameter("ListDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtListDate.Text, "dd-MMM-yyyy", Nothing))
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
        objDB.AddParameter("TransListType", Data.SqlDbType.TinyInt, CInt(rbtTransactAs.SelectedValue))
        If txtMonthlyRental.Text = "" Then
            objDB.AddParameter("MonthlyRental", Data.SqlDbType.Decimal, DBNull.Value)
        Else
            objDB.AddParameter("MonthlyRental", Data.SqlDbType.Decimal, CDbl(txtMonthlyRental.Text.Trim))
        End If
        If txtDurationOfTenancy.Text = "" Then
            objDB.AddParameter("TenancyDuration", Data.SqlDbType.Decimal, DBNull.Value)
        Else
            objDB.AddParameter("TenancyDuration", Data.SqlDbType.Decimal, CDbl(txtDurationOfTenancy.Text.Trim))
        End If
        objDB.AddParameter("TenancyDurationType", Data.SqlDbType.TinyInt, CInt(ddlModeOfPayment.SelectedValue))
        If txtRequisition.Text = "" Then
            objDB.AddParameter("Requisition", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("Requisition", Data.SqlDbType.NChar, txtRequisition.Text.ToUpper.Trim)
        End If
        objDB.AddParameter("PremiseUse", Data.SqlDbType.TinyInt, CInt(ddlUseOfPremis.SelectedValue))
        If txtTerminationClause.Text = "" Then
            objDB.AddParameter("TerminationClause", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TerminationClause", Data.SqlDbType.NVarChar, txtTerminationClause.Text.ToUpper.Trim)
        End If
        If chkLandlordCompany.Checked Then
            objDB.AddParameter("LandlordType", Data.SqlDbType.TinyInt, 1)
            objDB.AddParameter("LandlordName1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordName2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordName3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordCompany", Data.SqlDbType.NVarChar, txtLandlordCompanyName.Text.ToUpper.Trim)
            objDB.AddParameter("LandlordNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordCompanyNo", Data.SqlDbType.NVarChar, txtLandlordCompanyNo.Text.ToUpper.Trim)
        Else
            objDB.AddParameter("LandlordType", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("LandlordName1", Data.SqlDbType.NVarChar, txtLandlordName1.Text.ToUpper.Trim)
            objDB.AddParameter("LandlordName2", Data.SqlDbType.NVarChar, txtLandlordName2.Text.ToUpper.Trim)
            objDB.AddParameter("LandlordName3", Data.SqlDbType.NVarChar, txtLandlordName3.Text.ToUpper.Trim)
            objDB.AddParameter("LandlordCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordNRIC1", Data.SqlDbType.NVarChar, txtLandlordNric1.Text.ToUpper.Trim)
            objDB.AddParameter("LandlordNRIC2", Data.SqlDbType.NVarChar, txtLandlordNric2.Text.ToUpper.Trim)
            objDB.AddParameter("LandlordNRIC3", Data.SqlDbType.NVarChar, txtLandlordNric3.Text.ToUpper.Trim)
            objDB.AddParameter("LandlordCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
        End If
        If txtLandlordContactPerson.Text = "" Then
            objDB.AddParameter("LandlordContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordContactPerson", Data.SqlDbType.NVarChar, txtLandlordContactPerson.Text.ToUpper.Trim)
        End If
        If txtLandlordAddress.Text = "" Then
            objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, txtLandlordAddress.Text.ToUpper.Trim)
        End If
        If txtLandlordPhone.Text = "" Then
            objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordPhone", Data.SqlDbType.NVarChar, txtLandlordPhone.Text.ToUpper.Trim)
        End If
        If txtLandlordMobile.Text = "" Then
            objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, txtLandlordMobile.Text.ToUpper.Trim)
        End If
        If txtLandlordFax.Text = "" Then
            objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, txtLandlordFax.Text.ToUpper.Trim)
        End If
        If txtLandlordEmail.Text = "" Then
            objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordEmail", Data.SqlDbType.NVarChar, txtLandlordEmail.Text.ToUpper.Trim)
        End If
        If txtLandlordIncomeTaxNo.Text = "" Then
            objDB.AddParameter("LandlordIncomeTax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordIncomeTax", Data.SqlDbType.NVarChar, txtLandlordIncomeTaxNo.Text.ToUpper.Trim)
        End If
        If txtLandlordViewMeetTele.Text = "" Then
            objDB.AddParameter("LandlordViewMeetTele", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("LandlordViewMeetTele", Data.SqlDbType.NVarChar, txtLandlordViewMeetTele.Text.ToUpper.Trim)
        End If
        If ddlLandlordRefer.SelectedValue = "1" Then
            objDB.AddParameter("LandlordReferral", Data.SqlDbType.TinyInt, 1)
            If txtLandlordReferName.Text = "" Then
                objDB.AddParameter("LandlordReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordReferralName", Data.SqlDbType.NVarChar, txtLandlordReferName.Text.ToUpper.Trim)
            End If
            If txtLandlordReferNRIC.Text = "" Then
                objDB.AddParameter("LandlordReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordReferralNRIC", Data.SqlDbType.NVarChar, txtLandlordReferNRIC.Text.ToUpper.Trim)
            End If
            If txtLandlordReferContact.Text = "" Then
                objDB.AddParameter("LandlordReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordReferralContact", Data.SqlDbType.NVarChar, txtLandlordReferContact.Text.ToUpper.Trim)
            End If
            objDB.AddParameter("LandlordReferralStatus", Data.SqlDbType.TinyInt, ddlLandlordReferStatus.SelectedValue)
            If txtLandlordReferAmt.Text = "" Then
                objDB.AddParameter("LandlordReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("LandlordReferralAmount", Data.SqlDbType.Decimal, CDbl(txtLandlordReferAmt.Text.Trim))
            End If
        Else
            objDB.AddParameter("LandlordReferral", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("LandlordReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("LandlordReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            objDB.AddParameter("LandlordReferralStatus", Data.SqlDbType.TinyInt, ddlLandlordReferStatus.SelectedValue)
        End If
        If chkTenantCompany.Checked Then
            objDB.AddParameter("TenantType", Data.SqlDbType.TinyInt, 1)
            objDB.AddParameter("TenantName1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantName2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantName3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantCompany", Data.SqlDbType.NVarChar, txtTenantCompanyName.Text.ToUpper.Trim)
            objDB.AddParameter("TenantNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantCompanyNo", Data.SqlDbType.NVarChar, txtTenantCompanyNo.Text.ToUpper.Trim)
        Else
            objDB.AddParameter("TenantType", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("TenantName1", Data.SqlDbType.NVarChar, txtTenantName1.Text.ToUpper.Trim)
            objDB.AddParameter("TenantName2", Data.SqlDbType.NVarChar, txtTenantName2.Text.ToUpper.Trim)
            objDB.AddParameter("TenantName3", Data.SqlDbType.NVarChar, txtTenantName3.Text.ToUpper.Trim)
            objDB.AddParameter("TenantCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantNRIC1", Data.SqlDbType.NVarChar, txtTenantNric1.Text.ToUpper.Trim)
            objDB.AddParameter("TenantNRIC2", Data.SqlDbType.NVarChar, txtTenantNric2.Text.ToUpper.Trim)
            objDB.AddParameter("TenantNRIC3", Data.SqlDbType.NVarChar, txtTenantNric3.Text.ToUpper.Trim)
            objDB.AddParameter("TenantCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
        End If
        If txtTenantContact.Text = "" Then
            objDB.AddParameter("TenantContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantContactPerson", Data.SqlDbType.NVarChar, txtTenantContact.Text.ToUpper.Trim)
        End If
        If txtTenantAddress.Text = "" Then
            objDB.AddParameter("TenantAddress", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantAddress", Data.SqlDbType.NVarChar, txtTenantAddress.Text.ToUpper.Trim)
        End If
        If txtTenantPhone.Text = "" Then
            objDB.AddParameter("TenantPhone", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantPhone", Data.SqlDbType.NVarChar, txtTenantPhone.Text.ToUpper.Trim)
        End If
        If txtTenantMobile.Text = "" Then
            objDB.AddParameter("TenantMobile", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantMobile", Data.SqlDbType.NVarChar, txtTenantMobile.Text.ToUpper.Trim)
        End If
        If txtTenantFax.Text = "" Then
            objDB.AddParameter("TenantFax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantFax", Data.SqlDbType.NVarChar, txtTenantFax.Text.ToUpper.Trim)
        End If
        If txtTenantEmail.Text = "" Then
            objDB.AddParameter("TenantEmail", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantEmail", Data.SqlDbType.NVarChar, txtTenantEmail.Text.ToUpper.Trim)
        End If
        If txtTenantIncomeTax.Text = "" Then
            objDB.AddParameter("TenantIncomeTax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantIncomeTax", Data.SqlDbType.NVarChar, txtTenantIncomeTax.Text.ToUpper.Trim)
        End If
        If txtTenantViewMeetTele.Text = "" Then
            objDB.AddParameter("TenantViewMeetTele", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("TenantViewMeetTele", Data.SqlDbType.NVarChar, txtTenantViewMeetTele.Text.ToUpper.Trim)
        End If
        If ddlTenantRefer.SelectedValue = "1" Then
            objDB.AddParameter("TenantReferral", Data.SqlDbType.TinyInt, 1)
            If txtTenantReferName.Text = "" Then
                objDB.AddParameter("TenantReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantReferralName", Data.SqlDbType.NVarChar, txtTenantReferName.Text.ToUpper.Trim)
            End If
            If txtTenantReferNRIC.Text = "" Then
                objDB.AddParameter("TenantReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantReferralNRIC", Data.SqlDbType.NVarChar, txtTenantReferNRIC.Text.ToUpper.Trim)
            End If
            If txtTenantReferContact.Text = "" Then
                objDB.AddParameter("TenantReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantReferralContact", Data.SqlDbType.NVarChar, txtTenantReferContact.Text.ToUpper.Trim)
            End If
            objDB.AddParameter("TenantReferralStatus", Data.SqlDbType.TinyInt, ddlTenantReferStatus.SelectedValue)
            If txtTenantReferAmt.Text = "" Then
                objDB.AddParameter("TenantReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("TenantReferralAmount", Data.SqlDbType.Decimal, CDbl(txtTenantReferAmt.Text.Trim))
            End If
        Else
            objDB.AddParameter("TenantReferral", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("TenantReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("TenantReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            objDB.AddParameter("TenantReferralStatus", Data.SqlDbType.TinyInt, ddlTenantReferStatus.SelectedValue)
        End If
        'Fee
        If txtLandlordAgencyFee.Text = "" Then
            objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(txtLandlordAgencyFee.Text.Trim))
        End If
        If txtLandLordTAFee.Text = "" Then
            objDB.AddParameter("LandlordTAFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("LandlordTAFee", Data.SqlDbType.Decimal, CDbl(txtLandLordTAFee.Text.Trim))
        End If
        If txtLandlordGst.Text = "" Then
            objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(txtLandlordGst.Text.Trim))
        End If
        If chkLandlordGstPaid.Checked Then
            objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 1)
        Else
            objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 0)
        End If
        If lblListingPercent.Text = "" Then
            objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(lblListingPercent.Text.Trim))
        End If
        If lblLandlordReferralAmt.Text = "" Then
            objDB.AddParameter("LandlordReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("LandlordReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblLandlordReferralAmt.Text.Trim))
        End If
        If txtTenantDisbursement.Text = "" Then
            objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(txtTenantDisbursement.Text.Trim))
        End If
        If lblTenantReferralAmt.Text = "" Then
            objDB.AddParameter("TenantReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("TenantReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblTenantReferralAmt.Text.Trim))
        End If
        If txtTenantMonthValue.Text = "" Then
            objDB.AddParameter("DepositMonth", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("DepositMonth", Data.SqlDbType.Decimal, CDbl(txtTenantMonthValue.Text.Trim))
        End If
        If txtTenantMonthDeposit.Text = "" Then
            objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(txtTenantMonthDeposit.Text.Trim))
        End If
        If txtTenantAdvance.Text = "" Then
            objDB.AddParameter("Advance", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("Advance", Data.SqlDbType.Decimal, CDbl(txtTenantAdvance.Text.Trim))
        End If
        If txtTenantAdvanceValue.Text = "" Then
            objDB.AddParameter("AdvanceMonth", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("AdvanceMonth", Data.SqlDbType.Decimal, CDbl(txtTenantAdvanceValue.Text.Trim))
        End If
        If txtTenantWaterElec.Text = "" Then
            objDB.AddParameter("WaterElectric", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("WaterElectric", Data.SqlDbType.Decimal, CDbl(txtTenantWaterElec.Text.Trim))
        End If
        If txtTenantTel.Text = "" Then
            objDB.AddParameter("Tel", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("Tel", Data.SqlDbType.Decimal, CDbl(txtTenantTel.Text.Trim))
        End If
        If txtTenantTAFee.Text = "" Then
            objDB.AddParameter("TenantTAFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("TenantTAFee", Data.SqlDbType.Decimal, CDbl(txtTenantTAFee.Text.Trim))
        End If
        If lblTotalAgencyFee.Text = "" Then
            objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(lblTotalAgencyFee.Text.Trim))
        End If
        If lblForLister.Text = "" Then
            objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(lblForLister.Text.Trim))
        End If
        If lblForReferral.Text = "" Then
            objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(lblForReferral.Text.Trim))
        End If
        If lblForGorv.Text = "" Then
            objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(lblForGorv.Text.Trim))
        End If
        If lblGrossAmount.Text = "" Then
            objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(lblGrossAmount.Text.Trim))
        End If
        If lblTotalTAFee.Text = "" Then
            objDB.AddParameter("TotalTA", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("TotalTA", Data.SqlDbType.Decimal, CDbl(lblTotalTAFee.Text.Trim))
        End If
        If lblStampDuty.Text = "" Then
            objDB.AddParameter("StampDuty", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("StampDuty", Data.SqlDbType.Decimal, CDbl(lblStampDuty.Text.Trim))
        End If
        objDB.ExecuteQuery()
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim strBack As String = Session("Back").ToString
        Dim arr() As String = strBack.Split("ڡ")
        Response.Redirect(arr(0).ToString)
    End Sub
End Class
